package com.platform.hjt.sys.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.platform.hjt.base.controller.ReturnBody;
import com.platform.hjt.base.service.BaseService;
import com.platform.hjt.sys.dao.SysStateDAO;
import com.platform.hjt.sys.model.SysState;
import com.hjt.tools.dao.Page;
import com.hjt.tools.dao.PropertyFilter;
import com.hjt.tools.date.DateCreator;

@Service
public class SysStateService extends BaseService{

	@Resource
	private SysStateDAO sysStateDAO;
	
	public ReturnBody saveSysState(SysState sysState){
		if(StringUtils.isNotBlank(sysState.getSysStateId())){
			sysStateDAO.updatePerproties(sysState);
			return  new ReturnBody(true, "更新成功");
		}else{
			sysState.setIsDel(false);
			sysState.setCreateTime(DateCreator.getCurrentTime());
			sysState.setSysCompanyInfo(getSessionSysCompanyInfo());
			sysStateDAO.saveJ(sysState);
			return  new ReturnBody(true, "添加成功");
		}
	}
	
	public ReturnBody delSysState(SysState sysState){
		sysState.setIsDel(true);
		sysStateDAO.updatePerproties(sysState);
		return  new ReturnBody(true, "删除成功");
	}
	
	public Page<SysState> getSysStateList(Page<SysState> page, List<PropertyFilter> propertyFilterList){
		return sysStateDAO.findPage(page, propertyFilterList);
	}
	
	public List<SysState> getSysStateList(List<PropertyFilter> filters){
		return sysStateDAO.find(filters);
	}
	
	public SysState getSysState(List<PropertyFilter> filters){
		return sysStateDAO.findUniqueBy(filters);
	}
	
	public SysState getSysState(String propertyName, Object value){
		return sysStateDAO.findUniqueBy(propertyName, value);
	}
	
	public List<SysState> getSysStateList(String tableName, String tableColumn){
		List<PropertyFilter> filters = new ArrayList<PropertyFilter>();
		filters.add(new PropertyFilter("EQS_tableName", tableName));
		filters.add(new PropertyFilter("EQS_tableColumn", tableColumn));
		filters.add(new PropertyFilter("EQS_sysCompanyInfo.sysCompanyInfoId", getSessionSysCompanyInfo().getSysCompanyInfoId()));
		filters.add(new PropertyFilter("EQB_isDel", "false"));
		return getSysStateList(filters);
	}
	
}
